//
//  LKMytradeCountSonRightViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/22.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKMytradeCountSonRightViewController.h"
#import "LKTradeRightWebViewCell.h"
#import "UIImage+Tool.h"
@interface LKMytradeCountSonRightViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,copy)NSString *amount_trend;
@property(nonatomic,copy)NSString *number_trend;
@property(nonatomic,strong)UIView *btnsView;
@property(nonatomic,strong)LKBaseButton *sevenDayBtn;
@property(nonatomic,strong)LKBaseButton *fourteenDayBtn;
@property(nonatomic,strong)LKBaseButton *thirtyDayDayBtn;
@property(nonatomic,strong)LKBaseButton *sixtyDayBtn;
@property(nonatomic,copy)NSString *selecteTitile;
@end

@implementation LKMytradeCountSonRightViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.selecteTitile = @"7日";
    [self createButtonsView];
    [self createMyTableView];
    [self getMyDataInformationQWithType:@"1"];
    // Do any additional setup after loading the view.
}

-(void)createButtonsView{
    WS(weakSelf)
    self.btnsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    self.btnsView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.btnsView];
    self.sevenDayBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@"7日" titleColor:[UIColor blackColor] layercorne:20 font:[UIFont fontWithName:@"PingFangSC-Medium" size:15] backgroudColor:[UIColor whiteColor] AndActionBlock:^(UIButton * _Nonnull btn) {
        btn.selected = !btn.selected;
        if (btn.selected) {
            weakSelf.selecteTitile = @"7日";
            btn.backgroundColor = [UIColor redColor];
            weakSelf.fourteenDayBtn.selected = NO;
            weakSelf.fourteenDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.thirtyDayDayBtn.selected = NO;
            weakSelf.thirtyDayDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.sixtyDayBtn.selected = NO;
            weakSelf.sixtyDayBtn.backgroundColor = [UIColor whiteColor];
            [weakSelf getMyDataInformationQWithType:@"1"];
        }else{

        }
        
    }];
    self.sevenDayBtn.selected = YES;
    self.sevenDayBtn.backgroundColor = [UIColor redColor];
    [self.sevenDayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    self.fourteenDayBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@"14日" titleColor:[UIColor blackColor] layercorne:20 font:[UIFont fontWithName:@"PingFangSC-Medium" size:15] backgroudColor:[UIColor whiteColor] AndActionBlock:^(UIButton * _Nonnull btn) {
        btn.selected = !btn.selected;
        if (btn.selected) {
            weakSelf.selecteTitile = @"14日";
            btn.backgroundColor = [UIColor redColor];
            weakSelf.sevenDayBtn.selected = NO;
            weakSelf.sevenDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.thirtyDayDayBtn.selected = NO;
            weakSelf.thirtyDayDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.sixtyDayBtn.selected = NO;
            weakSelf.sixtyDayBtn.backgroundColor = [UIColor whiteColor];
            [weakSelf getMyDataInformationQWithType:@"2"];
        }else{
            
        }
    }];
        [self.fourteenDayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    self.thirtyDayDayBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@"30日" titleColor:[UIColor blackColor] layercorne:20 font:[UIFont fontWithName:@"PingFangSC-Medium" size:15] backgroudColor:[UIColor whiteColor] AndActionBlock:^(UIButton * _Nonnull btn) {
                btn.selected = !btn.selected;
        if (btn.selected) {
            weakSelf.selecteTitile = @"30日";
            btn.backgroundColor = [UIColor redColor];
            weakSelf.fourteenDayBtn.selected = NO;
            weakSelf.fourteenDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.sevenDayBtn.selected = NO;
            weakSelf.sevenDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.sixtyDayBtn.selected = NO;
            weakSelf.sixtyDayBtn.backgroundColor = [UIColor whiteColor];
            [weakSelf getMyDataInformationQWithType:@"3"];
        }else{
            
        }
    }];
        [self.thirtyDayDayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    self.sixtyDayBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@"60日" titleColor:[UIColor blackColor] layercorne:20 font:[UIFont fontWithName:@"PingFangSC-Medium" size:15] backgroudColor:[UIColor whiteColor] AndActionBlock:^(UIButton * _Nonnull btn) {
                btn.selected = !btn.selected;
        if (btn.selected) {
            weakSelf.selecteTitile = @"60日";
            btn.backgroundColor = [UIColor redColor];
            weakSelf.fourteenDayBtn.selected = NO;
            weakSelf.fourteenDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.thirtyDayDayBtn.selected = NO;
            weakSelf.thirtyDayDayBtn.backgroundColor = [UIColor whiteColor];
            weakSelf.sevenDayBtn.selected = NO;
            weakSelf.sevenDayBtn.backgroundColor = [UIColor whiteColor];
            [weakSelf getMyDataInformationQWithType:@"4"];
        }else{
            
        }
    }];
    [self.sixtyDayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.btnsView addSubview:self.sevenDayBtn];
    [self.btnsView addSubview:self.fourteenDayBtn];
    [self.btnsView addSubview:self.thirtyDayDayBtn];
    [self.btnsView addSubview:self.sixtyDayBtn];
    NSArray *btnsArray = @[self.sevenDayBtn,self.fourteenDayBtn,self.thirtyDayDayBtn,self.sixtyDayBtn];
    [btnsArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:40 leadSpacing:20 tailSpacing:20];
    [btnsArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.btnsView.mas_top).offset(5);
        make.height.equalTo(@40);
    }];
    
    
}
-(void)createMyTableView{
    self.tableView = [LKBaseTableview setTableviewWithFrame:CGRectZero style:UITableViewStyleGrouped registercellClasss:@[@"LKTradeRightWebViewCell"]];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:_tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.btnsView.mas_bottom).offset(10);
        make.bottom.equalTo(self.view).offset(-10);
    }];
    [self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        LKTradeRightWebViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKTradeRightWebViewCell"];
        cell.url = self.amount_trend;
        cell.header = [NSString stringWithFormat:@"%@%@",self.selecteTitile,@"交易金额趋势"];
        return cell;
    }
    if (indexPath.section == 1) {
        LKTradeRightWebViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKTradeRightWebViewCell"];
        cell.url = self.number_trend;
        cell.header = [NSString stringWithFormat:@"%@%@",self.selecteTitile,@"交易笔数趋势"];
        return cell;
    }
    LKTradeRightWebViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKTradeRightWebViewCell"];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 400.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    return [[UIView alloc] init];

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.000000001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1.0f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}


/// 获取报表数据
-(void)getMyDataInformationQWithType:(NSString *)type{
    NSDictionary *param = @{@"type":type};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyTradeCountUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        if ([responseObject[@"code"] isEqualToString:@"success"]) {
            self.amount_trend = responseObject[@"data"][@"amount_trend"];
            self.number_trend = responseObject[@"data"][@"number_trend"];
            [self.tableView reloadData];
        }else{
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
        }
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
